// pages/touch/touch.js
const API = require("../../http/API")
const http = require("../../http/http")
Page({
	data: {
		arr:["大触直播","大触专访","热门大触"],
		current:"大触直播",
		zhibo:[],
		live:[],
		page:1,
		zhuanfang:[],
		remen:[]
	},
	onLoad(options) {
		this.getlist()
		this.getzhuanfang()
		this.getremen()
	},
	clicktitle(e){
		this.setData({
			current:e.currentTarget.id,
			page:1
		})
		this.getlist()
		this.getzhuanfang()
	},
	// 发送首页请求获取数据
	getlist(){
		http(API.jijiang,{
			page:this.data.page
		}).then(res=>{
			if (this.data.page == 1){
				this.setData({
					zhibo:res.data.course.data,
					live:res.data.live
				})
			}else {
				if(res.data.course.data.length){
					this.setData({zhibo:this.data.zhibo.concat(res.data.course.data)})
				}else {
		        wx.showToast({
			          title: '没有更多数据',
			          icon: 'none'
			        })
				}
			}
		})
	},
	// 获取热门大触
	getremen(){
		http(API.remendachu,{
			link:"paging",
			page:this.data.page
		}).then(res=>{
			if (this.data.page == 1){
				this.setData({
					remen:res.data.data
				})
			}else {
				if(res.data.data.length){
					this.setData({remen:this.data.remen.concat(res.data.data)})
				}else {
		        wx.showToast({
			          title: '没有更多数据',
			          icon: 'none'
			        })
				}
			}
		})
	},
	// 专访页
	getzhuanfang(){
		http(API.zhuanfang,{
			page:this.data.page
		}).then(res=>{
			if (this.data.page == 1){
				this.setData({
					zhuanfang:res.data.data
				})
			}else {
				if(res.data.data.length){
					this.setData({zhuanfang:this.data.zhuanfang.concat(res.data.data)})
				}else {
		        wx.showToast({
			          title: '没有更多数据',
			          icon: 'none'
			        })
				}
			}
		})
	},
	// 触底加载
	onReachBottom(){
		this.setData({page:this.data.page * 1 + 1})
		if (this.data.current == "大触直播"){
			this.getlist()
		}else if(this.data.current == "大触专访"){
			this.getzhuanfang()
		}else{
			this.getremen()
		}
	}
})